#####################
'''
1.重点是i < len(s) - 1
2.左边小于右边数字时减去，左边大于右边时加上
3。字典通过键查找值时，dict[key]
'''
#####################
class Solution(object):
    def romanToInt(self, s):
        """
        :type s: str
        :rtype: int
        """
        sum_num = 0
        dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
        for i in range(len(s)):
            if i < len(s) - 1 and dict[s[i]] < dict[s[i+1]]:
                sum_num -= dict[s[i]]
                print('1:',sum_num)
            else:
                sum_num += dict[s[i]]
                print('2:',sum_num)
        return sum_num
        # return v for k, v in dict.items() if k == s
        # for k, v in dict.items():
        #     if k == s:
        #         return v
        #     else:
        #         for i in range(len(s)):
        #             if k == s[i] or k == s[i] + s[i+1]:
        #                 a += v
        # return a

def main():
    s = input('s = ')
    print(Solution().romanToInt(s))


if __name__ =='__main__':
    main()